﻿Imports System.Data.OleDb
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports AjaxControlToolkit

Public Class ContactUs
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Me.Page.User.IsInRole("UserPlus") Or Me.Page.User.IsInRole("Admin")) Then
            gwComment.Visible = True
        Else
            gwComment.Visible = False
        End If
    End Sub

    Protected Sub btnAddNew_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnContactUs.Click

        'Insert record inside SiteComments

        Dim username As String = "guest"

        If Me.Page.User.Identity.Name <> "" Then
            username = User.Identity.Name
        End If

        Dim timeNow As String = Date.Now
        timeNow = timeNow.Replace("#", "")

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("dbDusanCS").ConnectionString)
        oleDbConn.Open()

        Dim SqlString = "Insert into SiteComment(UserName,CommentText,CommentTime) Values (@param1,@param2,@param3)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@param1", username)
        cmd.Parameters.AddWithValue("@param2", txtContactUs.Text)
        cmd.Parameters.AddWithValue("@param3", Convert.ToDateTime(timeNow))
        cmd.ExecuteNonQuery()

        Dim str_message As String = "Thank you for your comment"
        Response.Write("<script>alert('" & str_message & "')</script>")

        txtContactUs.Text = ""

        oleDbConn.Close()

        Response.Redirect("ThankYou.aspx?back=ContactUs.aspx&message=added new comment")

    End Sub

End Class